package com.ruoyi.common.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.region.Region;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "tencent")
public class TencentCloudConfig {

    @Value("${tencent.secretId}")
    private String secretId;
    @Value("${tencent.secretKey}")
    private String secretKey;
    @Value("${tencent.region}")
    private String region;
    @Value("${tencent.bucketName}")
    private String bucketName;

    @Bean
    public COSClient cosClient(){
        // 认证对象
        BasicCOSCredentials credentials = new BasicCOSCredentials(secretId,secretKey);
        // 地域对象
        Region region = new Region(this.region);
        ClientConfig clientConfig = new ClientConfig(region);
        return new COSClient(credentials,clientConfig);
    }

    @Bean
    public Credential credential(){
        return new Credential(secretId,secretKey);
    }

    @Bean
    public OcrClient orcClient(Credential credential){
        return new OcrClient(credential,region);
    }

    public String getSecretId() {
        return secretId;
    }

    public void setSecretId(String secretId) {
        this.secretId = secretId;
    }

    public String getSecretName() {
        return secretKey;
    }

    public void setSecretName(String secretName) {
        this.secretKey = secretName;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }
}
